/**
 * Created by Administrator on 2018/4/13.
 */
import React from 'react'
import { connect } from 'react-redux'
import { addTodo } from '../actions'

const AddTodo = ({ dispatch }) => {
	let input;

	return (
		<div>
			<form action=""
				onSubmit={e=>{
					e.preventDefault()
					if (!input.value.trim()) {
						return
					}
					dispatch(addTodo(input.value))
					input.value = ''
				}}
			>
				<input ref={node => input = node}/>
				<button type="submit">Add Todo</button>
			</form>
		</div>
	)
}

export default connect()(AddTodo)

